"""
员工管理模块 接口对象层
"""
import requests

class ihrmEmpApi(object):
    # 添加员工
    @classmethod
    def add_emp(cls,header,json_data):
        url="https://ihrm-java.itheima.net/api/sys/user"
        resp=requests.post(url=url,headers=header,json=json_data)
        return resp

    # 查询员工
    @classmethod
    def select_emp(cls,emp_id,header):
        url = "https://ihrm-java.itheima.net/api/sys/user/"+emp_id
        resp = requests.get(url=url, headers=header)
        return resp

    # 查询员工列表
    @classmethod
    def select_emp_list(cls,header):
        url = "https://ihrm-java.itheima.net/api/sys/user?page=10&size=3"
        resp = requests.get(url=url, headers=header)
        return resp

    # 修改员工
    @classmethod
    def modify_emp(cls,emp_id,header,json_data):
        url = "https://ihrm-java.itheima.net/api/sys/user/"+emp_id
        resp = requests.put(url=url, headers=header, json=json_data)
        return resp

    # 删除员工
    @classmethod
    def delete_emp(cls,emp_id,header):
        url = "https://ihrm-java.itheima.net/api/sys/user/"+emp_id
        resp = requests.delete(url=url, headers=header)
        return resp

if __name__ == '__main__':
    header={"Content-Type":"application/json","Authorization":"Bearer 0c5be60c-36d1-4e4b-8637-0f74467e325a"}

    # 添加员工
    data_add={"username":"张三","mobile":"13800001238","workNumber":"1234"}
    resp=ihrmEmpApi.add_emp(header,data_add)
    print(f"添加员工：{resp.json()}")

    # 查询员工
    emp_id="1066370498633486336"
    resp=ihrmEmpApi.select_emp(emp_id,header)
    print(f"查询员工：{resp.json()}")

    # 查询员工列表
    resp=ihrmEmpApi.select_emp_list(header)
    print(f"查询员工列表：{resp.json()}")

    # 修改员工
    emp_id = "1943209681184063488"
    data={"username":"李四"}
    resp=ihrmEmpApi.modify_emp(emp_id,header,data)
    print(f"修改员工：{resp.json()}")

    # 删除员工
    emp_id = "1943209681184063488"
    resp=ihrmEmpApi.delete_emp(emp_id,header)
    print(f"删除员工：{resp.json()}")
